<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="运营中心" prop="run_id">
                <el-input-number v-model="form.run_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="年" prop="year">
                <el-input-number v-model="form.year"></el-input-number>
        	</el-form-item>
            <el-form-item label="月" prop="m">
                <el-input v-model="form.m" clearable></el-input>
        	</el-form-item>
            <el-form-item label="天" prop="day">
                <el-input v-model="form.day" clearable></el-input>
        	</el-form-item>
            <el-form-item label="日期" prop="date">
                <el-date-picker v-model="form.date" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="时间" prop="time">
                <el-date-picker v-model="form.time" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="更新时间" prop="updatetime">
                <el-date-picker v-model="form.updatetime" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="上月累计激励金" prop="last_month_total_excite_money">
                <el-input-number v-model="form.last_month_total_excite_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="后台设置的激励金发放比例" prop="admin_set_excite_money_send_ratio">
                <el-input-number v-model="form.admin_set_excite_money_send_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="当前激励金发放比例" prop="now_excite_money_send_ratio">
                <el-input-number v-model="form.now_excite_money_send_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="待分配激励金" prop="unallocate_excite_money">
                <el-input-number v-model="form.unallocate_excite_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="本月累计激励金" prop="month_total_total_excite_money">
                <el-input-number v-model="form.month_total_total_excite_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="激励金结余" prop="surplus_excite_money">
                <el-input-number v-model="form.surplus_excite_money"></el-input-number>
        	</el-form-item>
            <el-form-item label="上月消费总额" prop="last_month_total_consume">
                <el-input-number v-model="form.last_month_total_consume"></el-input-number>
        	</el-form-item>
            <el-form-item label="本月消费总额" prop="month_total_consume">
                <el-input-number v-model="form.month_total_consume"></el-input-number>
        	</el-form-item>
            <el-form-item label="消费占比" prop="consume_ratio">
                <el-input-number v-model="form.consume_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="消费增长率" prop="consume_inc_ratio">
                <el-input-number v-model="form.consume_inc_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="获取消费发放比例" prop="consume_send_ratio">
                <el-input-number v-model="form.consume_send_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="当前收益_消费" prop="now_income_consume">
                <el-input-number v-model="form.now_income_consume"></el-input-number>
        	</el-form-item>
            <el-form-item label="上月营业总额" prop="last_month_total_trade">
                <el-input-number v-model="form.last_month_total_trade"></el-input-number>
        	</el-form-item>
            <el-form-item label="本月营业总额" prop="month_total_trade">
                <el-input-number v-model="form.month_total_trade"></el-input-number>
        	</el-form-item>
            <el-form-item label="营业占比" prop="trade_ratio">
                <el-input-number v-model="form.trade_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="营业增长率" prop="trade_inc_ratio">
                <el-input-number v-model="form.trade_inc_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="获取营业发放比例" prop="trade_send_ratio">
                <el-input-number v-model="form.trade_send_ratio"></el-input-number>
        	</el-form-item>
            <el-form-item label="当前收益_营业" prop="now_income_trade">
                <el-input-number v-model="form.now_income_trade"></el-input-number>
        	</el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					run_id: '',
					year: '',
					m: '',
					day: '',
					date: '',
					time: '',
					updatetime: '',
					last_month_total_excite_money: '',
					admin_set_excite_money_send_ratio: '',
					now_excite_money_send_ratio: '',
					unallocate_excite_money: '',
					month_total_total_excite_money: '',
					surplus_excite_money: '',
					last_month_total_consume: '',
					month_total_consume: '',
					consume_ratio: '',
					consume_inc_ratio: '',
					consume_send_ratio: '',
					now_income_consume: '',
					last_month_total_trade: '',
					month_total_trade: '',
					trade_ratio: '',
					trade_inc_ratio: '',
					trade_send_ratio: '',
					now_income_trade: '',
                },
                rules: {
                },
            }
        },
        methods: {
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.run_excite_money_bill[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>